import 'package:flutter/material.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';

enum AssetDirection {
  ltr(Axis.horizontal, false),
  rtl(Axis.horizontal, true),
  ttb(Axis.vertical, false),
  btt(Axis.vertical, true);

  final Axis axis;
  final bool needReverse;

  const AssetDirection(this.axis, this.needReverse);
}

class AssetItem extends StatelessWidget {
  const AssetItem(
      {super.key,
      required this.asset,
      this.name,
      required this.assetSize,
      this.onTap,
      this.textStyle,
      this.space = 4,
      this.direction = AssetDirection.ttb,
      this.padding});

  final String asset;
  final double assetSize;
  final String? name;
  final TextStyle? textStyle;
  final double space;
  final AssetDirection direction;
  final EdgeInsets? padding;
  final Function()? onTap;

  @override
  Widget build(BuildContext context) {
    List<Widget> list = [
      Image.asset(Utils.getImgPath(asset), width: assetSize, height: assetSize),
      SizedBox(
          width: direction.axis == Axis.horizontal ? space : 0,
          height: direction.axis == Axis.vertical ? space : 0),
      if (name.hasValue) QsText.style(name, style: textStyle)
    ];
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: onTap,
      child: Padding(
        padding: padding ?? EdgeInsets.zero,
        child: Flex(
            mainAxisSize: MainAxisSize.min,
            direction: direction.axis,
            children: (direction.needReverse) ? list.reversed.toList() : list),
      ),
    );
  }
}
